﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Manager.App_Code;
using System.Linq;

namespace Manager.FormAdd_Edit
{
    public partial class frm_SearchCustomer : DevExpress.XtraEditors.XtraForm
    {
        NewPearl_HotelDataContext db = new NewPearl_HotelDataContext();
        public KhachHang khachHang;

        public frm_SearchCustomer()
        {
            InitializeComponent();
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            if (txtID.Text == "" || cmbLoaiId.Text == "")
                MessageBox.Show("Vui lòng nhập vào số CMND hoặc passport");
            else
            {
                if (cmbLoaiId.SelectedIndex == 0)
                    khachHang = db.KhachHangs.SingleOrDefault(t => t.CMND == txtID.Text);
                else
                    khachHang = db.KhachHangs.SingleOrDefault(t => t.Passport == txtID.Text);
                if (khachHang == null)
                    MessageBox.Show("Khách hàng không tồn tại.");
                else
                    this.Close();
            }
        }

        private void frm_SearchCustomer_Load(object sender, EventArgs e)
        {            
            cmbLoaiId.SelectedIndex = 0;
        }

        private void txtID_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }
    }
}